import sys
sys.path.append("../..")
import numpy as np
import pandas as pd
from tensor import Tensor
from optimizer import Adam
import function as func
import nn




lr = 0.1
loops = 10001

#读取数据集
x_array = pd.read_csv('data/MNIST_train_x.csv').values.reshape(59999,784)
y_array = pd.read_csv('data/MNIST_train_y.csv').values.reshape(59999,1)
y_array = func.conversion(y_array.astype(np.int16),9)#转换为损失函数可用的y_map

#转换为Tensor类型
x = Tensor(x_array.shape)
y = Tensor(y_array.shape)
x.inputValue(x_array/255)
y.inputValue(y_array)

#搭建前向传播过程
layer1 = nn.linear(784,16,activation_func='ReLU')(x)
layer2 = nn.linear(16,16,activation_func='ReLU')(layer1)
out = nn.linear(16,10)(layer2)
loss_func = nn.MSELoss()
loss = loss_func(out,y)

optimizer = Adam(lr)

for i in range(loops):
	optimizer.zeroGrad()
	x.forward()
	loss.backward()
	optimizer.step()
	if i%100==0:
		loss.show_mean()





































